<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/TR/htmL1/DTD/xhtml1-transitional.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %> 
<%--
    page description : 휴가관리 - 관리자 - 휴가 배정 (pop_up)
    author      : ych D
    date        : 2009-01-22
    file name   : vaca_alloc_p.jsp
--%>
<html>
<head>
	<s:head theme="ajax" />
	<base target="_self" />
	<link rel="stylesheet" type="text/css" href="/inc/css/common.css" />
	<link rel="stylesheet" type="text/css" href="style/style.css" />
	<link rel="stylesheet" type="text/css" href="/inc/css/dhtmlxcalendar.css" />
	
	<script type="text/javascript" src="/inc/js/common.js"></script>
	<script type="text/javascript" src="/js/common.js"></script>
	<script type="text/javascript" src="/js/dhtmlXCommon.js"></script>
	<script type="text/javascript" src="/js/dhtmlxcalendar.js"></script>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>휴가배정</title>
<!-- --------------------J A V A S C R I P T START-------------------- -->
    <script type="text/javascript">

	/*********************************************CALENDER******************************************************/
	/////////////////////달력////////////////////////////////////////////////
		function doOnLoad()
		{
			// 달력
			cal1 = new dhtmlxCalendarObject('alloc_date', false, {isYearEditable: true});
			cal1.setYearsRange(2000, 2050);
			cal1.setPosition(20,-82);
			cal1.draw();
			cal1.setOnClickHandler(selectDate1);

			cal2 = new dhtmlxCalendarObject('alloc_date', false, {isYearEditable: true});
			cal2.setYearsRange(2000, 2050);
			cal2.setPosition(20,-82);
			cal2.draw();
			// cal2.setOnClickHandler(selectDate2);
	
			document.getElementById('alloc_date').onfocus = function() { if (cal2.isVisible()) cal2.hide(); }
	
			document.body.onclick = function(){calendarHide("cal1,cal2","D");};
		}
	
		function selectDate1(date)
		{
			document.getElementById('alloc_date').value = cal1.getFormatedDate(null,date);
			dateFrom = new Date(date);
			dateTo = null;
			cal2.setSensitive(dateFrom, dateTo);
			cal1.hide();
			return true;
		}
	
	/////////////////////달력////////////////////////////////////////////////
	/*********************************************CALENDER******************************************************/

		//숫자체크 함수
		function checkNumber(input){
			for(var i=0;i<input.length;i++){
				if(input.charAt(i)!="."){
					if(input.charAt(i)==" ")
						return false;
					if(isNaN(input.charAt(i)))
						return false;
				}
			}
			return true;
		}

		//숫자만 입력
		function GetOnlyNumeric(ths){
			if (checkNumber(ths.value)){}
			else{
				alert("숫자만 입력 가능합니다.");
				ths.value = "";
				ths.focus();
			}
			return false;
		}

        /*
		휴가배정 INSERT/UPDATE
        */
		function fnc_submit(f) {

			var cnt = 0;
			var len = f.add_alloc_memo.value.length;
			var temp = f.add_alloc_memo.value;
			var alloc = f.alloc_date.value;
			var s_date = f.vaca_s_date.value;
			var e_date = f.vaca_e_date.value;
			var sub_alloc = alloc.substring(0,4)+alloc.substring(5,7)+alloc.substring(8,10);

			if(sub_alloc < s_date || sub_alloc > e_date){
				alert("배정기준일은 배정 시작일~종료일 사이일만 가능합니다.");
				f.alloc_date.focus();
				return false;
			}
			
			if(f.add_alloc_num.value == ""){
				alert("추가배정일수를 입력해주세요.");
				f.add_alloc_num.focus();
				return false;
			}
        	
			if(f.add_alloc_memo.value == ""){
				alert("추가배정사유를 입력해주세요.");
				f.add_alloc_memo.focus();
				return false;
			}else{
                for(i=0;i<len;i++){
                    if(temp.charAt(i)==" "){
                         cnt++;
                    }
                }
   			}
  			if(len==cnt){
                alert("배정사유란에 공백은 허용하지 않습니다.");
                f.add_alloc_memo.focus();
                return false;
   			}
            //if(!frm_validate(f)) {
            //    return false;
            //}

			//f.target = "_self";
			f.action = "insert_alloc_vacation.action"   //form action 설정.
			f.submit();
            
			return false;
		}
        
        //submit이전에 validate
        function frm_validate(f) {
            
            var sel_val = f.svaca.options[f.svaca.selectedIndex].value; //select tag에서 선택된 value.
            
            var alloc_num	=	f.alloc_num.value;
            
            if (sel_val == null || sel_val == "" || sel_val.length == 0) {
                alert("<s:text name="alert.message.selectVacationType" />");      //휴가유형이 선택되었는지 확인함.
                f.svaca.focus();                	//해당 태그로 포커스함.
                return false;
            } else if (alloc_num == null || alloc_num == "" || alloc_num.length == 0) {
                alert("<s:text name="alert.message.inputAllocNum" />");         //배정일수 입력이 없으면 경고창 띄움.
                f.alloc_num.focus();                //해당 태그로 포커스함.
                f.alloc_num.select();
                return false;            
           /*
            } else if(alloc_num.match(/\d+/g) != alloc_num) {	//js regular
            	alert("<s : text name="alert.message.notNumeric" />");
            	f.alloc_num.select();
            	return false;
           */
            } else if(!confirm("<s:text name="alert.message.questionApply" />")) {
                return false;
            }
            return true;
        }

		//휴가 배정 저장후 실행되는 부분.
		function fnc_apply_change(){
	    	
			//var args 	= window.dialogArguments;		//123,1234,1232,12321

			//document.getElementById("syear").value 		= 	args.document.getElementById("syear").value;
			//document.getElementById("s_chk").value 	= 	args.document.getElementById("s_chk").value;
			//document.getElementById("s_chk").value 		= 	args.args
	    	
			/*
			document.getElementById("steam").value 		= 	args.document.getElementById("steam").value;
			document.getElementById("semp_no").value 	= 	args.document.getElementById("semp_no").value;
			*/
			var rtn_msg 								= document.getElementById("rtn_msg").value;	//저장되었는지 알려줌.
	       	
			if(rtn_msg.length != 0) {
				alert(rtn_msg);
				window.close();
				//opener.dojo.event.topic.publish("show_list");
				opener.window.call_dojo();		//부모창 스크립트 실행.
			} else {
				//가운데 정렬
				if (document.layers) { 
					var x = screen.width / 2 - outerWidth / 2; 
					var y = screen.height / 2 - outerHeight / 2; 
				} else { 
					var x = screen.width / 2 - document.body.offsetWidth / 2; 
					var y = -75 + screen.height / 2 - document.body.offsetHeight / 2; 
				} 
				self.moveTo(x, y); 
			}
		}


    </script>
<!-- --------------------J A V A S C R I P T END-------------------- -->
</head>
<body onload="doOnLoad();fnc_apply_change();">
	<s:form name="frm" id="frm" method="post" theme="simple" onsubmit="return fnc_submit(this)">
	<s:hidden id="syear" 	name="syear" 	value="%{syar}"		/><!-- 근무년도 -->
	<s:hidden id="s_chk" 	name="s_chk" 	value="%{svaca}"	/><!-- 후가유형 -->
	<s:hidden id="rtn_msg"	name="rtn_msg" 						/><!-- return value alert message -->
	<s:hidden id="ch_emp_no" 	name="ch_emp_no" 	value="%{ch_emp_no}"		/><!-- 체크된 emp_no -->
	<div id="popup_350se_top_v3"></div>
	<div id="popup_350se_bg_v3">
		<div id="popup_325se_v3">
			<div id="popup_325se_box_v3">
				<ul>
			    	<li class="txt">성명/부서</li>
			    	<li>
			    		<!--s:property value="emp_nm"/><input type="hidden" name="a_emp_no" value="<s:property value="emp_no"/>" /-->
			    		<s:property value="vaca_info.emp_nm"/><input type="hidden" name="emp_nm">/<s:property value="vaca_info.group_nm"/><input type="hidden" name="group_nm">
			    	</li>
		    	</ul>
		    	<!--ul>
	    			<li class="txt">부서</li>
	    			<li>
						<s:property value="vaca_info.group_nm"/><input type="hidden" name="group_nm">
	    			</li>
    			</ul-->

				<ul>
					<li class="txt">배정시작일</li>
					<li>
						<s:property value="vaca_info.vaca_s_date.substring(0,4)+'-'+vaca_info.vaca_s_date.substring(4,6)+'-'+vaca_info.vaca_s_date.substring(6,8)" />
						<input type="hidden" name="vaca_s_date" value="<s:property value="vaca_info.vaca_s_date" />">
					</li>
				</ul>
				<ul>
					<li class="txt">배정종료일</li>
					<li>
						<s:property value="vaca_info.vaca_e_date.substring(0,4)+'-'+vaca_info.vaca_e_date.substring(4,6)+'-'+vaca_info.vaca_e_date.substring(6,8)" />
						<input type="hidden" name="vaca_e_date" value="<s:property value="vaca_info.vaca_e_date" />">
					</li>
				</ul>
				<ul>
					<li class="txt">배정작업일</li>
					<li>
						<s:property value="alloc_date" />
					</li>
				</ul>
				<ul>
					<li class="txt">배정기준일</li>
					<li>
						<input type="text" size="12" maxlength="10" name="alloc_date" id="alloc_date" value="<s:property value="alloc_date" />" class="input_100se" style="height:20;background-image:url('images/calendar/calendar.gif');background-repeat:no-repeat;background-position:right 2px;cursor:hand" />
					</li>
				</ul>

				<ul>
					<li class="txt">휴가유형</li>
					<li><s:select name="svaca" cssClass="combobox100se"  	list="listVacation" listKey="cd" listValue="cd_nm" /></li>
				</ul>
				<ul>
					<li class="txt">추가배정일수</li>
					<li>
						<s:select name="add_alloc_num" cssClass="combobox100se"  	list="listAllocNum" listKey="alloc_num" listValue="alloc_num_nm" />
					</li>
				</ul>
				<ul>
					<li class="txt">추가배정사유</li>
					<li><s:textfield name="add_alloc_memo" size="1" maxlength="100" cssClass="input_200se" /></li>
				</ul>
				
				<div id="popup_btn">
					<input type="image" value="저장" src="/images/btn_save.gif" style="cursor: pointer;" />
				</div>
			</div>
		</div>
		</div>
		<br/><br/><br/><br/><br/>
	<!---------------Bottom : STR----------->
	<div id="popup_350se_bottom"><img src="/images/pop_btn_close.gif" style="cursor: pointer;" onclick="window.close();" /></div>
	<!---------------Bottom : END----------->                
	</s:form>
</body>
</html>